package com.itheima.delaytask.feign.fallbackfactory;

import com.itheima.delaytask.dto.Task;
import com.itheima.delaytask.feign.ZhzTaskService;
import com.itheima.response.ResponseMessage;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;

/**
 * @program: virtual-trade-parent
 * @description:
 * @author: zhanghz001
 * @create: 2021-07-11 22:27
 **/
// @Component
@Slf4j
public class ZhzTaskServiceFallbackFactory implements FallbackFactory<ZhzTaskService> {
    @Override
    public ZhzTaskService create(Throwable throwable) {
        
        return new ZhzTaskService() {
            @Override
            public ResponseMessage pushTask(Task task) {
                log.error("push task error by feign,task={},errormsg={}",
                        task, throwable.getMessage());
                return ResponseMessage.error(null);
            }
            
            @Override
            public ResponseMessage pollTask(Integer type, Integer priority) {
                
                log.error("poll task error by feign,type={},priority={},errormsg={}",
                        type, priority, throwable.getMessage());
                return ResponseMessage.error(null);
            }
            
            @Override
            public ResponseMessage cancelTask(Long taskId) {
                
                log.error("cancel task error by feign,taskId={},errormsg={}",
                        taskId, throwable.getMessage());
                return ResponseMessage.error(null);
            }
            
            @Override
            public ResponseMessage refresh() {
                
                log.error("refresh error by feign, ,errormsg={}",
                        throwable.getMessage());
                return ResponseMessage.error(null);
            }
        };
    }
}
